package com.firefly.web.controller.home.test;

import com.firefly.service.command.common.AliyunCodeCommand;
import com.firefly.service.command.common.AliyunOssCommand;
import com.firefly.util.handle.CommonResult;
import com.firefly.web.utils.OssUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @description: 测试阿里云sdk功能
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2023/5/15
 **/
@RestController
public class AliyunController {
    private final AliyunCodeCommand aliyunCodeCommand;
    private final OssUtils ossUtils;
    @Autowired
    public AliyunController(AliyunCodeCommand aliyunCodeCommand,OssUtils ossUtils){
        this.aliyunCodeCommand = aliyunCodeCommand;
        this.ossUtils = ossUtils;
    }
    @GetMapping("aliyun/sms")
    public Object testSms(HttpServletRequest request) throws Exception {
        String phone = request.getParameter("phone");
        return this.aliyunCodeCommand.sendSms(phone);
    }

    @PostMapping("aliyun/stream")
    public CommonResult testStream(@RequestParam("fireflyFile") MultipartFile file,@RequestParam(value = "dir",required = false) String dir) throws IOException {
//        return ossUtils.uploadStream(file,dir);
        return ossUtils.uploadTmpFile(file,dir);
    }
    @PostMapping("aliyun/file")
    public CommonResult testFile(HttpServletRequest request){
        return ossUtils.uploadFile(request.getParameter("dir"));
    }
}
